package com.zzg.springboot.entity;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToOne;
import javax.persistence.PrimaryKeyJoinColumn;
import javax.persistence.Table;
/**
 * 
 * @ClassName:  Product   
 * @Description: 单向：多个产品属于同一个产品类型   
 * @author: 世纪伟图 -zzg
 * @date:   2018年11月9日 下午3:25:04   
 *     
 * @Copyright: 2018 www.digipower.cn 
 * 注意：本内容仅限于深圳市世纪伟图科技开发有限公司内部使用，禁止用于其他的商业目的
 */
@Entity
@Table(name = "t_product")
public class Product {
	 @Id
	  @GeneratedValue
	  private Long id;
	  private String name;
	  @ManyToOne(optional = true) //指定关系(多对一)
	  @JoinColumn(name = "type_id") //指定关联的字段(外键字段)
	  private ProductType type;
	  
	  @ManyToOne(optional = true) // 指定关系(多对一)
	  @JoinTable(name = "product_type_middle", joinColumns = @JoinColumn(name = "product_id"), inverseJoinColumns = @JoinColumn(name = "type_id", unique = true)) //通过关联表(两个关联字段)
	  private ProductType middle;
	  
	  public Product() {
	  }

	  public Product(String name, ProductType type) {
	    this.name = name;
	    this.type = type;
	  }


	public ProductType getMiddle() {
		return middle;
	}

	public void setMiddle(ProductType middle) {
		this.middle = middle;
	}

	public Long getId() {
	    return id;
	  }

	  public void setId(Long id) {
	    this.id = id;
	  }

	  public String getName() {
	    return name;
	  }

	  public void setName(String name) {
	    this.name = name;
	  }

	  public ProductType getType() {
	    return type;
	  }

	  public void setType(ProductType type) {
	    this.type = type;
	  }

	  @Override
	  public String toString() {
	    return "Product [id=" + id + ", name=" + name + "]";
	  }

}
